<template>
  <div class="helper">
    <span class="left">有 {{unFinishedTodoLength}} 项未完成</span>
    <span class="tabs">
      <span
        v-for="state in states"
        :key="state.status"
        :class="[state.status, filter === state.status? 'actived': '']"
        @click="toggleFilter(state.status)"
      >
        {{state.txt}}
      </span>
    </span>
    <span class="clear" @click="clearAllCompleted">清空已完成</span>
  </div>
</template>

<script>
export default {
  props: {
    filter: {
      type: String,
      required: true
    },
    todos: {
      type: Array,
      required: true
    }
  },
  data () {
    return {
      states: [{
        status: 'all', 
        txt:'全部'
      }, {
        status: 'acitve', 
        txt:'未完成'
      }, {
        status: 'completed', 
        txt:'已完成'
      }]
    }
  },
  computed: {
    unFinishedTodoLength() {
      return this.todos.filter(todo => !todo.completed).length
    }
  },
  methods: {
    toggleFilter(status) {
      this.$emit('toggle', status)
    },
    clearAllCompleted () {
      this.$emit('clear')
    }
  }
}
</script>

<style lang="stylus" scoped>
.helper {
    font-weight: 100;
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    line-height: 30px;
    background-color: #ffffff;
    font-size: 14px;
    font-smoothing: antialiased;
}

.left, .clear, .tabs {
    padding: 0 10px;
}

.left .clear {
    width: 150px;
}

.left {
    text-align: center;
}

.clear {
    text-align: right;
    cursor: pointer;
}

.tabs {
    width: 200px;
    display: flex;
    justify-content: space-between;

    * {
        display: inline-block;
        padding: 0 10px;
        cursor: pointer;
        border: 1px solid rgba(175, 47, 47, 0);

        &.actived {
            border-color: rgba(175, 47, 47, 0.4);
            border-radius: 5px;
        }
    }
}
</style>